<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>编辑老人生活方式从表</title>
	<#include "/common/resource.ftl">
	<script type="text/javascript">
		$(function () {
			<#if (params.healthId)??>
				$.ajaxRequest({
					url: '${params.contextPath}/web/elderLifeStyle/query.json',
					data: {elderHealthId: "${params.healthId}"},
					success: function (data) {
						if (!data.success) {
							$.message(data.message);
							return;
						}
						var record = data.data;
						for (var key in record) {
                            if (key == 'physicalExerciseRate') {
                                // 体育锻炼频率
                                var physicalExerciseRate = record.physicalExerciseRate;
                                $("select[name='physicalExerciseRate']").val(physicalExerciseRate);
                            } else if (key == 'dietaryHabit') {
                                var dietaryHabit = record.dietaryHabit;
                                var dietaryHabitArray = dietaryHabit.split(",");
                                var dietaryHabitAll = $("input[name='dietaryHabit']");
                                for(var i=0; i<dietaryHabitArray.length; i++){
                                    debugger;
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(dietaryHabitAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(dietaryHabitArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'smokeStatus') {
                                // 吸烟状况
                                var smokeStatus = record.smokeStatus;
                                $("select[name='smokeStatus']").val(smokeStatus);
                            } else if (key == 'drinkStatus') {
                                // 饮酒状况
                                var drinkStatus = record.drinkStatus;
                                $("select[name='drinkStatus']").val(drinkStatus);
                            } else if (key == 'isAbstinence') {
                                // 是否戒酒
                                var isAbstinence = record.isAbstinence;
                                $("select[name='isAbstinence']").val(isAbstinence);
                            } else if (key == 'isDrunkennessInOneYear') {
                                // 近一年是否饮酒
                                var isDrunkennessInOneYear = record.isDrunkennessInOneYear;
                                $("select[name='isDrunkennessInOneYear']").val(isDrunkennessInOneYear);
                            } else if (key == 'drinkKind') {
                                var drinkKind = record.drinkKind;
                                var drinkKindArray = drinkKind.split(",");
                                var drinkKindAll = $("input[name='drinkKind']");
                                for(var i=0; i<drinkKindArray.length; i++){
                                    debugger;
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(drinkKindAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(drinkKindArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'isOccupationalHazardExposureHistory') {
                                var isOccupationalHazardExposureHistory = record.isOccupationalHazardExposureHistory;
                                $("select[name='isOccupationalHazardExposureHistory']").val(isOccupationalHazardExposureHistory);
                            } else if (key == 'isDustProtect') {
                                var isDustProtect = record.isDustProtect;
                                $("select[name='isDustProtect']").val(isDustProtect);
                            } else if (key == 'isRadiogenicProtect') {
                                var isRadiogenicProtect = record.isRadiogenicProtect;
                                $("select[name='isRadiogenicProtect']").val(isRadiogenicProtect);
                            } else if (key == 'isPhysicalFactorProtect') {
                                var isPhysicalFactorProtect = record.isPhysicalFactorProtect;
                                $("select[name='isPhysicalFactorProtect']").val(isPhysicalFactorProtect);
                            } else if (key == 'isChemicalSubstancesProtect') {
                                var isChemicalSubstancesProtect = record.isChemicalSubstancesProtect;
                                $("select[name='isChemicalSubstancesProtect']").val(isChemicalSubstancesProtect);
                            } else if (key == 'isOtherProtect') {
                                var isOtherProtect = record.isOtherProtect;
                                $("select[name='isOtherProtect']").val(isOtherProtect);
                            } else {
                                $("[name='" + key + "']").val(record[key]);
                            }


						}
                        var form = layui.form;
                        form.render();
					}
				});
			</#if>

            // 处理单选按钮回显问题
            function handleRadio(key, record) {
                var value = record.key;
                // 获取所有
                var keyAll = $("input[name='"+key+"']");
                $.each(keyAll,function(j,checkbox){
                    debugger
                    //获取单选框的value属性
                    var checkValue = $(checkbox).val();
                    if(value == checkValue){
                        $(checkbox).attr("checked",true);
                        $(checkbox).next().addClass('layui-form-radioed');
                    }
                });
            }
		});

	</script>
    <link rel="stylesheet" href="${params.contextPath}/static/plug/layui/css/layui.css">
    <style>
        .layui-form select {display:none !important;}
    </style>
</head>
<body>
	<div class="ui-form">
        <#if (params.healthId)??>
            <form class="layui-form ajax-form" action="${params.contextPath}/web/elderLifeStyle/<#if (params.id)??>modify<#else>save</#if>.json" method="post">
                <input type="hidden" name="elderHealthId" value="${params.healthId}" />
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div class="layui-row">
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">体育锻炼频率<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="physicalExerciseRate" class="layui-input">
                                            <option value="">请选择</option>
                                            <option value="每天">每天</option>
                                            <option value="每周一次以上">每周一次以上</option>
                                            <option value="偶尔">偶尔</option>
                                            <option value="不锻炼">不锻炼</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">每次锻炼时间(分钟)<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="physicalExerciseTime" placeholder="请输入每次锻炼时间" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">坚持锻炼(年)<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="physicalExerciseYears" placeholder="请输入坚持锻炼年数" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-row">
                            <div class="layui-col-md3">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">锻炼方式<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="physicalExerciseMod" placeholder="请输入锻炼方式" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md9">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">饮食习惯<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="checkbox" name="dietaryHabit" value="荤素均衡" title="荤素均衡">
                                        <input type="checkbox" name="dietaryHabit" value="荤食为主" title="荤食为主">
                                        <input type="checkbox" name="dietaryHabit" value="素食为主" title="素食为主">
                                        <input type="checkbox" name="dietaryHabit" value="嗜盐" title="嗜盐">
                                        <input type="checkbox" name="dietaryHabit" value="嗜油" title="嗜油">
                                        <input type="checkbox" name="dietaryHabit" value="嗜糖" title="嗜糖">
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-row">
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">吸烟状况<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="smokeStatus" class="layui-input">
                                            <option value="">请选择</option>
                                            <option value="从不吸烟">从不吸烟</option>
                                            <option value="已戒烟">已戒烟</option>
                                            <option value="吸烟">吸烟</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">日吸烟量(支)<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="smokeDailyNum" placeholder="请输入日吸烟量" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-row">
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">开始吸烟年龄(岁)<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="smokeStartAge" placeholder="请输入开始吸烟年龄" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">戒烟年龄(岁)<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="smokeEndAge" placeholder="请输入戒烟年龄" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-row">
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">饮酒状况<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="drinkStatus" class="layui-input">
                                            <option value="">请选择</option>
                                            <option value="从不">从不</option>
                                            <option value="偶尔">偶尔</option>
                                            <option value="经常">经常</option>
                                            <option value="每天">每天</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">日饮酒量(两)<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="drinkDailyNum" placeholder="请输入日饮酒量(两)" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">是否戒酒<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="isAbstinence" class="layui-input">
                                            <option value="">请选择</option>
                                            <option value="未戒酒">未戒酒</option>
                                            <option value="已戒酒">已戒酒</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-row">
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">戒酒年龄(岁)<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="abstinenceAge" placeholder="请输入戒酒年龄" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">开始饮酒年龄(岁)<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="drinkStartAge" placeholder="请输入开始饮酒年龄" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">近一年是否饮酒<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="isDrunkennessInOneYear" class="layui-input">
                                            <option value="">请选择</option>
                                            <option value="是">是</option>
                                            <option value="否">否</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-row">
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">饮酒种类<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="checkbox" name="drinkKind" value="白酒" title="白酒">
                                        <input type="checkbox" name="drinkKind" value="啤酒" title="啤酒">
                                        <input type="checkbox" name="drinkKind" value="红酒" title="红酒">
                                        <input type="checkbox" name="drinkKind" value="黄酒" title="黄酒">
                                        <input type="checkbox" name="drinkKind" value="其他" title="其他">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">其他酒类名称<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="drinkKindOtherName" placeholder="请输入其他酒类名称" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-row">
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">是否职业病危害因素接触史<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="isOccupationalHazardExposureHistory" class="layui-input">
                                            <option value="">请选择</option>
                                            <option value="无">无</option>
                                            <option value="有">有</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">职业病工种<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="occupationalHazardProfession" placeholder="请输入职业病工种" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">职业病从业年数<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="occupationalHazardYears" placeholder="请输入职业病从业年数" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-row">
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">粉尘种类<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="dustType" placeholder="请输入粉尘种类" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">是否粉尘防护<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="isDustProtect" class="layui-input">
                                            <option value="">请选择</option>
                                            <option value="无">无</option>
                                            <option value="有">有</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-row">
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">放射物质种类<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="radiogenicType" placeholder="请输入放射物质种类" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">是否放射物质防护<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="isRadiogenicProtect" class="layui-input">
                                            <option value="">请选择</option>
                                            <option value="无">无</option>
                                            <option value="有">有</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">物理因素种类<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="physicalFactorType" placeholder="请输入物理因素种类" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">是否物理因素防护<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="isPhysicalFactorProtect" class="layui-input">
                                            <option value="">请选择</option>
                                            <option value="无">无</option>
                                            <option value="有">有</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">化学物质种类<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="chemicalSubstancesType" placeholder="请输入化学物质种类" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">是否化学物质防护<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="isChemicalSubstancesProtect" class="layui-input">
                                            <option value="">请选择</option>
                                            <option value="无">无</option>
                                            <option value="有">有</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">其他毒物<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="text" name="otherType" placeholder="请输入其他毒物" class="layui-input"/>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">其他毒物是否防护<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <select name="isOtherProtect" class="layui-input">
                                            <option value="">请选择</option>
                                            <option value="无">无</option>
                                            <option value="有">有</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="submit" value="保存" class="layui-btn" />
                    </div>
                </div>
            </form>
        <#else>
            请先保存老人健康基本信息!
        </#if>
	</div>
</body>
<script src="${params.contextPath}/static/plug/layui/layui.all.js"></script>
<script>
    $(function () {
        var form = layui.form;
        form.render();
    })
</script>
</html>
